package Control;

import java.util.Date;

import javax.swing.JOptionPane;

import Entity.NeedyResident_CreateAccount;
import Form.NeedyResident_CreateUser_Form;

public class NeedyResident_CreateUser_Control {
	
	private NeedyResident_CreateUser_Form parser;
	
	public NeedyResident_CreateUser_Form getParser() {
		return parser;
	}

	public void setPaser(NeedyResident_CreateUser_Form parser) {
		this.parser = parser;
	}

	NeedyResident_CreateAccount resident = new NeedyResident_CreateAccount();
	
	public NeedyResident_CreateUser_Control(NeedyResident_CreateUser_Form parser){
		this.setPaser(parser);
		
	}
	
	public NeedyResident_CreateAccount createAccount(){
		resident.setNric(getParser().getTf_nric().getText());
		resident.setPassword(new String((getParser().getPf_password().getPassword())));
		resident.setContact_no(Integer.parseInt(getParser().getTf_contactNo().getText()));
		resident.setName(getParser().getTf_name().getText());
		resident.setEmail(getParser().getTf_email().getText());
		//How to get Date
		resident.setDob((Date)getParser().getSpinner().getValue());
		//How to get Text
		resident.setAddress(getParser().getTf_address().getText());
		//How to get Gender
		resident.setGender((getParser().getTf_gender().getText()).charAt(0));
		//How to get Double
		resident.setMonthlySalary(Double.parseDouble(getParser().getTf_monthlyIncome().getText()));
		//How to get int
		resident.setFamilySize(Integer.parseInt(getParser().getTf_familySize().getText()));
		
		boolean success = resident.createNeedyResident();
		
		if (success = true)
			JOptionPane.showMessageDialog(null, "Account Created");
		else
			JOptionPane.showMessageDialog(null, "Creation not successful, please try again.");
		
		return resident;
	}
}
